$.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

/////////////////////// Garagames dialog //////////////////////

/*
var allow_grg = $.cookie('grg_message');
var hash12 = $.cookie('bb_sessionhash');
	    console.log("Cookie doc ready");
		if (allow_grg != 'yes')
			{		
			    console.log("Cookies allows message");
				$.cookie('grg_message', 'yes', { path: '/', expires: 1 });
				if (confirm('VN-Zoom mới có thêm game Binh, Chắn và giải đấu Tá Lả hấp dẫn. Tặng 1000 gold cho thành viên mới. Hãy tham gia!')) 
				{ 
					window.location = 'http://www.vnzgames.com/?utm_source=vnzoom&utm_medium=popup&utm_campaign=dialog&partner=vnz&sessionhash='+hash12;
				}
			}
		else
		{
			console.log("Cookies prevents message");
		}

*/
$(function() {
  $('a.navtab').attr('href', function() {
    return this.href + '&sessionhash=' + hash12;
})
});

$("a").live('click',function(e){
    var url = $(this).attr("href");
    if (e.currentTarget.host != window.location.host) {
        _gaq.push(['_trackEvent', 'Outbound Links', e.currentTarget.host, url, 0]);
        if (e.metaKey || e.ctrlKey) {
             var newtab = true;
        }
        if (!newtab) {
             e.preventDefault();
             setTimeout('document.location = "' + url + '"', 100);
        }
    }
});

//////////////////////////////////////////////////////////////////////////////////////////////
// bk ads //////////////////
/////////////////////////////////////////////////////////////////////////////////////////////

//document.write('<script src="http://media.ichodientuvn.com/webskins/javascripts/popup/vnzoom.js" type="text/javascript"></script>');

/*
var allow_popupunder = $.cookie('open_popupunder');
var current_date = new Date();

if (allow_popupunder != 'yes')
{
	var _click_popunder = false;
	
	$(document).click(function(){
		if (_click_popunder == false)
		{
			_click_popunder = true;

			var exp_date = new Date(current_date.getFullYear(), current_date.getMonth(), (current_date.getDate()+1), 1, 1, 0, 0);
			$.cookie('open_popupunder', 'yes', { path: '/', expires: exp_date });

			var popunder="http://cungdinhke.tik.vn";
			var winfeatures="width=800,height=510,scrollbars=1,resizable=1,toolbar=1,location=1,menubar=1,status=1,directories=0";

			var win2 = window.open(popunder, "name", winfeatures);
			if (win2)
			{
				win2.blur();
			}     
			
			window.focus();
		}
	});
}
*/







